﻿Imports System.Data.SqlClient

Public Class PhieuNhapXeDAO

    Public Shared Function LoadAtPhieuNhapXe(ByVal _ma As String) As DataTable

        Dim cn As SqlConnection = DataProvider.GetCn()
        Dim strSQL As String = "usp_LoadAtPhieuNhapXe"
        Dim da As New SqlDataAdapter(strSQL, cn)
        da.SelectCommand.CommandType = CommandType.StoredProcedure
        da.SelectCommand.Parameters.Add("@Ma", SqlDbType.VarChar)
        da.SelectCommand.Parameters("@Ma").Value = _ma
        Dim dt As New DataTable
        da.Fill(dt)
        cn.Close()
        Return dt

    End Function

    Public Shared Function LapPhieuNhapXe(ByVal pn As PhieuNhapXeDTO) As String

        Dim cmd As New SqlCommand("usp_LapPhieuNhap", DataProvider.GetCn())
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.Add("@NgayLapPhieu", SqlDbType.Date)
        cmd.Parameters.Add("@MaPhieuNhap", SqlDbType.VarChar).Direction = ParameterDirection.Output
        cmd.Parameters("@NgayLapPhieu").Value = pn.m_dNgayLap
        cmd.Parameters("@MaPhieuNhap").Size = 10
        cmd.ExecuteNonQuery()
        DataProvider.CloseCn()

        Return cmd.Parameters("@MaPhieuNhap").Value.ToString()

    End Function


End Class
